﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace HGZP.PLL
{
    public class TreeOperator
    {
        //向下选中
        public void UserSelectSub(TreeNode myTreeNode)
        {
            foreach (TreeNode mySubTreeNode in myTreeNode.Nodes)
            {
                if (mySubTreeNode.Checked != true)
                {
                    mySubTreeNode.Checked = true;
                }
                //
                UserSelectSub(mySubTreeNode);
            }
        }
        //向下取消选中
        public void UserUnSelectSub(TreeNode myTreeNode)
        {
            foreach (TreeNode mySubTreeNode in myTreeNode.Nodes)
            {
                if (mySubTreeNode.Checked != false)
                {
                    mySubTreeNode.Checked = false;
                }
                //
                UserUnSelectSub(mySubTreeNode);
            }
        }
        //向上选中
        public void UserSelectParent(TreeNode myTreeNode)
        {
            if (myTreeNode.Level == 0) { return; }
            if (myTreeNode.Parent.Checked == false)
            {
                myTreeNode.Parent.Checked = true;
                UserSelectParent(myTreeNode.Parent);
            }

        }
        //向上取消选中
        public void UserUnSelectParent(TreeNode myTreeNode)
        {
            if (myTreeNode.Level == 0) { return; }
            int iCount = 0;
            foreach (TreeNode mySubTreeNode in myTreeNode.Parent.Nodes)
            {

                if (mySubTreeNode.Checked == true)
                {
                    iCount++;
                }
            }
            //
            if (iCount == 0)
            {
                myTreeNode.Parent.Checked = false;
                UserUnSelectParent(myTreeNode.Parent);
            }
            //



        }
        //全部选中
        public void UserSelectAll(TreeView myTreeView)
        {
            foreach (TreeNode myTreeNode in myTreeView.Nodes)
            {
                if (myTreeNode.Checked == false)
                {
                    myTreeNode.Checked = true;
                }
                //
                UserSelectAll(myTreeNode);
            }
        }
        //全部选中
        public void UserSelectAll(TreeNode myTreeNode)
        {
            foreach (TreeNode mySubTreeNode in myTreeNode.Nodes)
            {
                if (mySubTreeNode.Checked == false)
                {
                    mySubTreeNode.Checked = true;
                }
                UserSelectAll(mySubTreeNode);
            }
        }
        //全部取消选中
        public void UserUnSelectAll(TreeView myTreeView)
        {
            foreach (TreeNode myTreeNode in myTreeView.Nodes)
            {
                if (myTreeNode.Checked == true)
                {
                    myTreeNode.Checked = false;
                }
                //
                UserUnSelectAll(myTreeNode);
            }
        }
        //全部取消选中
        public void UserUnSelectAll(TreeNode myTreeNode)
        {
            foreach (TreeNode mySubTreeNode in myTreeNode.Nodes)
            {
                if (mySubTreeNode.Checked == true)
                {
                    mySubTreeNode.Checked = false;
                }
                UserUnSelectAll(mySubTreeNode);
            }
        }
    }
}
